

<!DOCTYPE html>

<html>

<head>

    {include file="public/head" /}

<body>

<div class="mfc fl goods bc-back">

    <div class="cbox mfc fl">

        <div class="mfc goods-headpic">



            <img src="{$info.single_pic}">



        </div>

        <div class="mfc goods-infor gap">

            <h1 class="lh20">{$info.title}</h1>

            <p class="imark lh20">{$info.describe}</p>

            <p class="price c-red lh30"><span class="fa fa-cny"> </span> {$info.price}</p>

        </div>

    </div>

    <div class="cbox mfc fl gap">

        <div class="goods-specs mfc fl">

<!--            <span class="c-gray">商品规格:</span><a href="">10斤</a> <a href="">20斤</a> <a href="">30斤</a>-->

        </div>

        <div class="goods-atext mfc fl">

            {:html($info.content)}

        </div>

    </div>

</div>

<div class="mfc bmenu fl">

    <div class="cbox botton">

        <div class="mfc tc buy-box">

            <div class="mfc2 fl">

                <button onclick="types(1)" class="bc-yellow ACT" act_v="body:ofh|.Tbox:active"><span class="fa fa-shopping-cart"> </span> 加入购物车</button>

            </div>

            <div class="mfc2 fl">

                <button onclick="types(2)" class="ACT" act_v="body:ofh|.Tbox:active"><span class="fa fa-cny"> </span> 立即购买</button>

            </div>

        </div>

    </div>

</div>



<div class="Tbox">

    <div class="mask"></div>

    <div class="show bs">

        <div class="close ACT" act_v="body:ofh|.Tbox:active"><img src="__MOBILE__/img/icon_close_black.png"></div>

        <div class="goods-choose">

            <div class="mfc goods-headinfo gap fl">

                <div class="cell">

                    <div class="sicon"><img src="{$info.attr_values_pic}"></div>

                    <div class="mfc info">

                        <p class="fs12 lh24">{:StrLength($info.title,10)}</p>

                        <p class="prive c-red"><span class="fa fa-cny"></span> <span class="fs16">{$info.price}</span></p>

                    </div>

                </div>

            </div>

            <div class="mfc goods-attrib fl">

                {volist name="info.api_goods_attr.data" id="vo" key="k1"}

                <div class="cell attrss">

                    {if $info.api_goods_attr.type != 444}

                    <div class="attr_title" attr_title="{$vo.attr_name}">{$vo.attr_name}：</div>

                    <div class="mfc goods-attrib-multi">

                        {volist name="vo.attr_list" id="vo2" key="k2"}

                        <span><input class="attr_value" {eq name="$k2" value="1"}checked{/eq}  type="radio" name="attr{$k1}" attr="{$vo2.attr_value}" value="{$vo2.attr_value}" words="{$vo2.attr_value}"></span>

                        {/volist}

                    </div>

                    {/if}

                    {if $info.api_goods_attr.type == 44}

                    {volist name="vo.attr_list" id="vo2" key="k2"}

                    <input style="display: none;"  class="attr_value" {eq name="$k2" value="1"}checked{/eq}  type="radio" name="attr{$k1}" attr="{$vo2.attr_value}" value="{$vo2.attr_value}" words="{$vo2.attr_value}">

                    {/volist}

                    {/if}

                </div>

                {/volist}

                <div class="cell">

                    <div class="lh24 goods-choose-tags">

                        <span class="imark">数量：</span>

                        <span class="button fa fa-minus-square-o" onclick="minus()"></span>

                        <span class="number" id="number">1</span>

                        <span class="button fa fa-plus-square-o" onclick="plus()"></span>

<!--                        <span class="imark">(库存199)</span>-->

                    </div>

                </div>

                <div class="cell">

                    <div class="mfc goods-choose-option">

                        <p class="prive c-red"><span class="fa fa-cny"></span> <span class="fs16">{$info.price}</span></p>

                        <button type="button" cart_type="0" class="btnbox pabs-r-box">确定</button>

                    </div>

                </div>

            </div>

        </div>

    </div>

</div>

</body>

</html>

<script>

    function plus() {

        var v = parseInt($('#number').text());

        $('#number').text(v + 1);

    }



    function minus() {

        var v = parseInt($('#number').text());

        if (v <= 1) {

            layer.msg('不能在减了');

            return;

        }

        $('#number').text(v - 1);

    }



    //确定按钮类型1或者2 默认0

    function types(type){



        $('.pabs-r-box').attr('cart_type',type);

    }



    //确定按钮ajax

    $('.pabs-r-box').click(function () {

        var goods_id = "{$info.id}";

        var attr_values_arg = [];

        var number = parseInt($('#number').text());

        var type = $(this).attr('cart_type');

        console.log('-----------------------');

        console.log(type);

        console.log('-----------------------');

        var sub = 0;

        var sub2 = 0;

        $('.attrss').each(function () {

             sub++;

             var attr_value = $(this).find("input[type=radio]:checked").val();

             var attr_name = $(this).find('.attr_title').attr('attr_title');

            // console.log(attr_name);

            // console.log(attr_value);



            if (typeof(attr_value) == "undefined")

            {

               layer.msg(attr_name+' : 请选择属性');

               return false;

            }

            sub2++;

            attr_values_arg.push(attr_value);

            //console.log(attr_value);

        });

        console.log(sub);

        console.log(sub2);

        if(sub == sub2){

            var attr_values = attr_values_arg.join(',');

            console.log(attr_values);

            $.ajax({

                type: "POST", //用POST方式传输

                dataType: "json", //数据格式:JSON

                url: "{:url('Cart/create')}", //目标地址

                data:{goods_id:goods_id,attr_values:attr_values,type:type,number:number},

                async: false,

                traditional :false,

                success: function (ret) {

                    console.log(ret);

                    if(ret.code == 200){

                        //layer.msg(ret.message);

                        console.log(ret.message);

                        setTimeout(function () {

                            $('.Tbox').removeClass('active');

                            if(ret.data.type == 1){

                                //window.location.href = "{:url('Cart/index')}";

                            }

                            if(ret.data.type == 2){

                                window.location.href = "{:url('Cart/order_list')}?cart_id_str="+ret.data.id;

                            }

                        },1000);

                    }

                }

            });

        }



    });



    //切换属性价格和图片库存等

    $('.attr_value').click(function () {

        var i = 0;

        var j = 0;

        var goods_id = "{$info.id}";

        var attr_values_arg = [];//属性数组

        $(this).parents('.goods-attrib').find('.attrss').each(function () {

            i++;

            var attr_value = $(this).find("input[type=radio]:checked").val();

            var attr_name = $(this).find('.attr_title').attr('attr_title');

            if (typeof(attr_value) == "undefined")

            {

                //layer.msg(attr_name+' : 请选择属性');return false;

            }else{

                j++;//选中的属性数量

            }

            attr_values_arg.push(attr_value);





        })

        var attr_values = attr_values_arg.join(',');

        console.log(attr_values);

        if(i == j){ //属性数量和选中数量



            $.ajax({

                type: "POST", //用POST方式传输

                dataType: "json", //数据格式:JSON

                url: "{:url('attr_values_find')}", //目标地址

                data:{goods_id:goods_id,attr_values:attr_values},

                async: false,

                traditional :false,

                // data:{distribution_type:distribution_type,order_number:order_number},

                success: function (ret) {

                    console.log(ret);

                    $('.fs16').text(ret.data.price);//查询属性ajax

                    $('.sicon>img').attr('src',ret.data.attr_values_pic);

                }

            });



        }

    });



    // $('.btnbox').on('click',function () {

    //     alert(1234);

    // });

</script>